package com.qiaofang.housewarehouse.service.impl;


import com.qiaofang.housewarehouse.dao.EsDAO;
import com.qiaofang.housewarehouse.dao.HbaseDao;
import com.qiaofang.housewarehouse.dao.domain.IndexCityRegion;
import com.qiaofang.housewarehouse.dao.domain.IndexCityRegionDistrict;
import com.qiaofang.housewarehouse.dao.utils.ConfigUtils;
import com.qiaofang.housewarehouse.service.CityQueryService;
import com.qiaofang.housewarehouse.service.compose.CityQueryCompose;
import com.qiaofang.housewarehouse.stub.constants.TableConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CityQueryServiceImpl implements CityQueryService{
    private static final Logger logger = LoggerFactory.getLogger(CityQueryServiceImpl.class);

    @Resource
    private HbaseDao hbaseDao;
    @Resource
    private EsDAO esDAO;

    @Override
    public  List<String>  listEntityCityByRow(String city) throws Exception {
        List<IndexCityRegion> indexCityRegionAliases = esDAO.searchRegionListByCityType(IndexCityRegion.class, ConfigUtils.getIndexHswhCity(), TableConstants.INDEX_TYPE_REGION, city);
        return CityQueryCompose.composeRegionList(indexCityRegionAliases);
    }

    @Override
    public List<String> listDistricCityByRow(String cityName, String regionName) throws Exception {
        List<IndexCityRegionDistrict> indexCityRegionDistricts = esDAO.searchDistrictListByCityAndRegionType(IndexCityRegionDistrict.class, ConfigUtils.getIndexHswhCity(), TableConstants.INDEX_TYPE_DISTRICT, cityName, regionName);
        return CityQueryCompose.composeDistricList(indexCityRegionDistricts);
    }
}
